<%@ page import="weaver.general.Util" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="com.api.workflow.util.YNHttpUtils" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    BaseBean baseBean = new BaseBean();
    //通过合同编号获取获取所有的剩余可支付金额
    JSONObject res = new JSONObject();
    try {
        String gys = Util.null2String(request.getParameter("gys"));
        String gsdm = Util.null2String(request.getParameter("gsdm"));
        String hb = Util.null2String(request.getParameter("hb"));
        Map<String, Object> map = new HashMap<>();
        map.put("LIFNR", gys);
        map.put("BUKRS", gsdm);
        map.put("WAERS", hb);
        JSONObject object = new JSONObject(map);
        baseBean.writeLog("YNFII010AAction==========object" + object.toJSONString());
        String post = YNHttpUtils.FII010A(object.toJSONString(), YNHttpUtils.token());
        baseBean.writeLog("YNFII010AAction==========post" + post);
        JSONObject jsonObject = JSONObject.parseObject(post);


        String STATUS = jsonObject.getString("STATUS");
        String MESSAGE = jsonObject.getString("MESSAGE");
        baseBean.writeLog("YNFII010AAction==========MESSAGE" + MESSAGE);


        if (!"S".equals(STATUS)) {
            res.put("api_status", false);
            res.put("data", MESSAGE);
            out.print(res.toString());
            return;
//
        }

        JSONArray data = jsonObject.getJSONArray("DATA");
        JSONObject firstElement = data.getJSONObject(0);
        firstElement.getString("LIFNR");
        firstElement.getString("WRBTR");
        firstElement.getString("ZGWRBTR");
        RecordSet rs = new RecordSet();
        rs.executeQuery("select bm,mc from uf_gsdmb where bm='" + firstElement.getString("BUKRS") + "'");
        JSONObject gsdmj = new JSONObject();
        JSONArray gsdmArray = new JSONArray();
        if (rs.next()) {
            gsdmj.put("id", rs.getString("bm"));
            gsdmj.put("name", rs.getString("mc"));
            gsdmArray.add(gsdm);
        }
        firstElement.put("gsdm", gsdmArray);
        res.put("api_status", true);
        res.put("data", firstElement);
    }catch (Exception e) {
        res.put("api_status", false);
        res.put("data", e.getMessage());
        baseBean.writeLog("YNFII010AAction==========e" + e.getMessage());
        baseBean.writeLog(e);
        e.printStackTrace();
    }

    out.print(res.toString());
    out.flush();

%>